package river_city_ransom.tests;

import river_city_ransom.contracts.Dimensions_C;
import river_city_ransom.contracts.Gangster_C;
import river_city_ransom.contracts.Objet_C;
import river_city_ransom.contracts.PersonnageJouable_C;
import river_city_ransom.contracts.Position_C;
import river_city_ransom.implementations.Dimensions_I;
import river_city_ransom.implementations.Gangster_I;
import river_city_ransom.implementations.Objet_I;
import river_city_ransom.implementations.PersonnageJouable_I;
import river_city_ransom.implementations.Position_I;
import river_city_ransom.services.Dimensions;
import river_city_ransom.services.Gangster;
import river_city_ransom.services.Objet;
import river_city_ransom.services.PersonnageJouable;
import river_city_ransom.services.Position;
import river_city_ransom.types.ObjetNom;
import exceptions.ComposantError;
import junit.framework.TestCase;


public class Personnage_T extends TestCase {
	public void test_deposerPointsDeVie_ok_1() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, pvd = 10;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			int pv_pre = p.pointsDeVie();
			p.deposerPointsDeVie(pvd);
			assertTrue(p.pointsDeVie() == Math.min(pv_pre + pvd, p.maxPointsDeVie()));
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_deposerPointsDeVie_ok_1\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_deposerPointsDeVie_ok_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, pvr = 25, pvd = 10;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.retirerPointsDeVie(pvr);
			int pv_pre = p.pointsDeVie();
			p.deposerPointsDeVie(pvd);
			assertTrue(p.pointsDeVie() == Math.min(pv_pre + pvd, p.maxPointsDeVie()));
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_deposerPointsDeVie_ok_2\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_deposerPointsDeVie_ko() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, pvd = -10;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.deposerPointsDeVie(pvd);
			System.err.println("Personnage::test_deposerPointsDeVie_ko\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_retirerPointsDeVie_ok_1() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, pvr = 10;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			int pv_pre = p.pointsDeVie();
			p.retirerPointsDeVie(pvr);
			assertTrue(p.pointsDeVie() == Math.max(0, pv_pre - pvr));
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_retirerPointsDeVie_ok_1\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_retirerPointsDeVie_ok_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.retirerPointsDeVie(pv);
			assertTrue(p.pointsDeVie() == 0);
			assertTrue(p.estVaincu() == true);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_retirerPointsDeVie_ok_2\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_ramasser_ok_1() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o = new Objet_C(new Objet_I(ObjetNom.CHAINE_DE_VELO));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.ramasser(o);
			assertTrue(p.choseEquipee().equals(o));
			assertTrue(p.estEquipe() == true);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_ramasser_ok_1\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_ramasser_ok_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o1 = new Objet_C(new Objet_I(ObjetNom.CHAINE_DE_VELO));
			Objet o2 = new Objet_C(new Objet_I(ObjetNom.POUBELLE_METALLIQUE));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.ramasser(o1);
			p.jeter();
			p.ramasser(o2);
			assertTrue(p.choseEquipee().equals(o2));
			assertTrue(p.estEquipe() == true);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_ramasser_ok_2\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_ramasser_ko_1() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o1 = new Objet_C(new Objet_I(ObjetNom.CHAINE_DE_VELO));
			Objet o2 = new Objet_C(new Objet_I(ObjetNom.POUBELLE_METALLIQUE));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.ramasser(o1);
			p.ramasser(o2);
			System.err.println("Personnage::test_ramasser_ko_1\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_ramasser_ko_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, g = 5;
			Objet o = new Objet_C(new Objet_I(ObjetNom.CHAINE_DE_VELO));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.geler(g);
			p.ramasser(o);
			System.err.println("Personnage::test_ramasser_ko_2\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_ramasser_ko_3() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o = new Objet_C(new Objet_I(ObjetNom.UN_DOLLAR));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.ramasser(o);
			System.err.println("Personnage::test_ramasser_ko_3\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_jeter_ok() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Objet o = new Objet_C(new Objet_I(ObjetNom.CHAINE_DE_VELO));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.ramasser(o);
			p.jeter();
			assertTrue(p.choseEquipee() == null);
			assertTrue(p.estEquipe() == false);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_jeter_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_jeter_ko() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.jeter();
			System.err.println("Personnage::test_jeter_ko\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_deplacer_ok_1() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Position po = new Position_C(new Position_I(5, 20, 10));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.deplacer(po);
			assertTrue(p.position().equals(po));
			assertTrue(p.versLaDroite() == true);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_deplacer_ok_1\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_deplacer_ok_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Position po1 = new Position_C(new Position_I(10, 20, 10));
			Position po2 = new Position_C(new Position_I(5, 10, 0));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.deplacer(po1);
			p.deplacer(po2);
			assertTrue(p.position().equals(po2));
			assertTrue(p.versLaDroite() == false);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_deplacer_ok_2\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_deplacer_ko() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100;
			Position po = new Position_C(new Position_I(5, 20, 10));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.retirerPointsDeVie(pv);
			p.deplacer(po);
			System.err.println("Personnage::test_deplacer_ko\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_geler_ok() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, g = 5;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.geler(g);
			assertTrue(p.estGele() == g);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_geler_ok\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_geler_ko() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, g = 0;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.geler(g);
			System.err.println("Personnage::test_geler_ko\n\tException non levée.");
			fail("Exception non levée.");
		}
		catch(ComposantError e) {
		}
	}

	public void test_degeler_ok_1() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, g = 5;
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.geler(g);
			int eg_pre = p.estGele();
			p.degeler();
			assertTrue(p.estGele() == Math.max(0, eg_pre - 1));
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_degeler_ok_1\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}

	public void test_degeler_ok_2() {
		try {
			String n = "Alex";
			Dimensions d = new Dimensions_C(new Dimensions_I(10, 50, 10));
			int f = 15, pv = 100, g = 5;
			Gangster ga = new Gangster_C(new Gangster_I("Generic Dude", d, f, pv));
			PersonnageJouable p = new PersonnageJouable_C(new PersonnageJouable_I(null, null, 0, 0));
			p.init(n, d, f, pv);
			p.geler(g);
			ga.ramasser(p);
			int eg_pre = p.estGele();
			p.degeler();
			assertTrue(p.estGele() == eg_pre);
		}
		catch(ComposantError e) {
			System.err.println("Personnage::test_degeler_ok_2\n\t" + e.getMessage());
			fail(e.getMessage());
		}
	}
}
